Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix hidden glob reexports 146164 #146212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sitetester wants to merge 4 commits into rust-lang:master
base: master
Choose a base branch
Loading
from sitetester:fix-hidden-glob-reexports-146164

Conversation

Copy link

@sitetester sitetester commented Sep 4, 2025
edited
Loading

Fixes: #146164

The hidden_glob_reexports lint will now skip generating a warning when the imported type points to the same type as public glob reexport

Let's create the following files to check the current behaviour

Current behaviour

  • fix/before/allow_when_same.rs
#![no_std] // Allows direct access to core OR Absolute path to core
#![allow(hidden_glob_reexports)]
pub use core::option::*;
use ::core::option::Option;
fn main() {
 // warning suppressed because of `allow`
 let _x: Option<i32> = Some(42);
}
  • fix/before/warn_when_same.rs
#![warn(hidden_glob_reexports)]
pub use std::option::*;
use ::std::option::Option;
fn main() {
 // Warns when same (current buggy behavior)
 // Even though importing the same item & there is no "shadowing"
 // Should Only warn when a different/private item actually shadows the glob reexport
 let _x: Option<i32> = Some(42);
}

Can test using

~/rust/build/host/stage1/bin/rustc --edition 2021 fix/before/allow_when_same.rs
img_9
~/rust/build/host/stage1/bin/rustc --edition 2021 fix/before/warn_when_same.rs 
img_8

Fix

  • Update compiler/rustc_resolve/src/imports.rs
  • Rebuild
./x build --stage 1 # Compiler + standard library + sysroot (complete setup)

Create these files

  • fix/after/not_warn_when_same.rs
#![warn(hidden_glob_reexports)]
pub use std::option::*;
use ::std::option::Option;
fn main() {
 // Should be no warning after fix
 let _x: Option<i32> = Some(42);
}
~/rust/build/host/stage1/bin/rustc --edition 2021 fix/after/not_warn_when_same.rs
img_10
  • fix/after/should_warn_when_private_shadows_glob.rs
#![deny(hidden_glob_reexports)]
pub mod upstream {
 mod inner { pub struct Foo {} pub struct Bar {} }
 pub use self::inner::*;
 struct Foo {} // private item shadows `inner::Foo`
}
// mod downstream {
// fn test() {
// let _ = crate::upstream::Foo; // inaccessible
// }
// }
pub fn main() {}
~/rust/build/host/stage1/bin/rustc --edition 2021 fix/after/should_warn_when_private_shadows_glob.rs
img_11

For development/quick testing,
hidden-glob-reexports-issue-146164.rs is the official test that goes into Rust, as every bug fix needs a test as per Rust standards. It's part of Rust's test suite that runs automatically

~/rust/build/host/stage1/bin/rustc ~/rust/tests/ui/lint/hidden-glob-reexports-issue-146164.rs
image

For official/CI testing

cd ~/rust # Must be in rust directory first 
./x test tests/ui/lint/hidden-glob-reexports-issue-146164.rs # Use relative path
cd ~/rust 
./x test tests/ui/lint/ --test-args="146164"

Fixes rust-lang#146164
The lint was incorrectly warning when importing the same item that's
already available through a glob re-export. This adds a check to only
warn when the explicit import and glob import resolve to different items.
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 4, 2025

This comment has been minimized.

This comment has been minimized.

@sitetester sitetester force-pushed the fix-hidden-glob-reexports-146164 branch from 967782f to 397204d Compare September 6, 2025 10:28
@sitetester sitetester marked this pull request as ready for review September 6, 2025 11:58
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 6, 2025
Copy link
Collaborator

rustbot commented Sep 6, 2025

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

The lint was incorrectly warning when importing the same item that's
already available through a glob re-export. This adds a check to only
warn when the explicit import and glob import resolve to different items.
@sitetester sitetester force-pushed the fix-hidden-glob-reexports-146164 branch from 397204d to e9af075 Compare September 6, 2025 12:07
Copy link
Author

@petrochenkov PR is open for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /